/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.helper.EncCommonHelper;
import com.minierp.model.MakeType;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class MakeTypeListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"MakeTypeList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderTop(1);
		cellStyle.setBorderRight(1);
		cellStyle.setBorderBottom(1);
		cellStyle.setBorderLeft(1);
		HSSFCellStyle bgStyle = workbook.createCellStyle();
		bgStyle.setAlignment(2);
		bgStyle.setFillForegroundColor(22);
		bgStyle.setFillPattern(1);
		bgStyle.setBorderTop(1);
		bgStyle.setBorderRight(1);
		bgStyle.setBorderBottom(1);
		bgStyle.setBorderLeft(1);
		HSSFCellStyle normStyle = workbook.createCellStyle();
		normStyle.setAlignment(2);
		normStyle.setBorderTop(1);
		normStyle.setBorderRight(1);
		normStyle.setBorderBottom(1);
		normStyle.setBorderLeft(1);
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		c.setCellStyle(cellStyle);
		c.setCellValue(new HSSFRichTextString("序号"));
		c = r.createCell(1);
		c.setCellStyle(cellStyle);
		c.setCellValue(new HSSFRichTextString("上级类别"));
		c = r.createCell(2);
		c.setCellStyle(cellStyle);
		c.setCellValue(new HSSFRichTextString("项目类型名称"));
		c = r.createCell(3);
		c.setCellStyle(cellStyle);
		c.setCellValue(new HSSFRichTextString("工作中心"));
		Object[] list = (Object[]) model.get("list");
		List mtList = (List) model.get("mtList");
		List wcList = (List) model.get("wcList");

		for (int os = 0; os < list.length; ++os) {
			MakeType bean = (MakeType) list[os];
			r = sheet.createRow(os + 1);
			c = r.createCell(0);
			c.setCellStyle(bgStyle);
			c.setCellValue(new HSSFRichTextString(bean.getSequCode()));
			c = r.createCell(1);
			c.setCellStyle(normStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.getSimpleObjectName(mtList, bean.getParentId())));
			c = r.createCell(2);
			c.setCellStyle(bgStyle);
			c.setCellValue(new HSSFRichTextString(bean.getTypeName()));
			c = r.createCell(3);
			c.setCellStyle(normStyle);
			c.setCellValue(new HSSFRichTextString(EncCommonHelper
					.getSimpleObjectName(wcList, bean.getWorkCenterId())));
		}

		sheet.setColumnWidth(0, 2000);
		sheet.setColumnWidth(1, 4000);
		sheet.setColumnWidth(2, 4000);
		sheet.setColumnWidth(3, 4000);
		ServletOutputStream arg16 = response.getOutputStream();
		workbook.write(arg16);
		arg16.flush();
		arg16.close();
	}
}